/*
 * MinIO Cloud Storage (C) 2016, 2018 MinIO, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React from "react"
import { connect } from "react-redux"
import logo1 from "../../img/logo1.svg"
import logo2 from "../../img/logo2.svg"
import logo3 from "../../img/logo3.svg"
import arrowl from "../../img/arrow-l.svg"
import wf from "../../img/wf.png"

export class Switch extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      discoveryDoc: {},
      clientId: "",
    }
  }


  jumpTo(x) {
    const { history } = this.props
    this.props.history.push(x)
  }
  openTo() {
    window.open('http://192.168.0.29:18630/j_security_check?j_username='+this.state.accessKeyLdap+'&j_password='+this.state.secretKeyLdap+'&basePath=%2F',"_blank")
      // window.location.href='http://192.168.0.29:18630/j_security_check?j_username='+this.state.accessKeyLdap+'&j_password='+this.state.secretKeyLdap+'&basePath=%2F';
    const { history } = this.props
  }
  switchBanner(e) {
    e.preventDefault()
    web.Logout()
    history.replace("/login")
  }
  componentWillMount() {
    document.body.classList.add("is-guest")
  }

  componentDidMount() {
    web.GetDiscoveryDoc().then(({ DiscoveryDoc, clientId }) => {
      this.setState({
        clientId,
        discoveryDoc: DiscoveryDoc
      })
    })
  }

  componentWillUnmount() {
    document.body.classList.remove("is-guest")
  }

  render() {
    return (
      <div className="login">
        <img className="wf" src={wf} alt="" />
        
        {this.state.loginsuccess && (
        <div className="banner">
        <h1>智能大数据存储管理平台</h1>
        <div className="banner-ct">
          <div className="banner-item" onClick={()=>this.openTo()}>
            <div className="bg bg2">
              <img src={logo2} alt="" />
            </div>
            <div className="banner-content">
              <h2>数据集成</h2>
              <p className="banner-btn">点击进入</p>
              <img src={arrowl} alt="" />
            </div>
          </div>
          <div className="banner-item" onClick={()=>this.jumpTo("/")}>
            <div className="bg bg1">
              <img src={logo1} alt="" />
            </div>
            <div className="banner-content">
              <h2>对象存储</h2>
              <p className="banner-btn">点击进入</p>
              <img src={arrowl} alt="" />
            </div>
          </div>
          <div className="banner-item">
            <div className="bg bg3">
              <img src={logo3} alt="" />
            </div>
            <div className="banner-content">
              <h2>数据分析</h2>
              <p className="banner-btn">点击进入</p>
              <img src={arrowl} alt="" />
            </div>
          </div>
        </div>
        <button className="tologin" onClick={this.switchBanner}>返回登录页</button>
      </div>
        )}

      </div>
    )
  }
}

const mapDispatchToProps = dispatch => {
  return {
    showAlert: (type, message) =>
      dispatch(actionsAlert.set({ type: type, message: message })),
    clearAlert: () => dispatch(actionsAlert.clear())
  }
}

export default connect(
  state => state,
  mapDispatchToProps
)(Login)
